﻿using AutoMapper;
using MediatR;
using Microsoft.Data.SqlClient;
using System.Data;
using T_vehicle.API.Application.Command.AccidentCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.AccidentCommandHandlers
{
    public class AddAccidentCommandHandlers:IRequestHandler<AddAccidentCommand,int>
    {
        private readonly IAccidentRepository accidentRepository;
        private readonly IMapper  mapper;

        public AddAccidentCommandHandlers(IAccidentRepository accidentRepository, IMapper mapper)
        {
            this.accidentRepository = accidentRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddAccidentCommand request, CancellationToken cancellationToken)
        {
            var Info = mapper.Map<Accident>(request);
            Info.CreateDate = DateTime.Now;
            return await accidentRepository.AddAsync(Info);

            //var Info = new Accident();
            //Info.AccidentTitle = request.AccidentTitle;
            //Info.LicenNumber = request.LicenNumber;
            //Info.Incident =request.Incident;
            //Info.IncidentDate = request.IncidentDate;
            //Info.Indemnify = request.Indemnify;
            //Info.loss = request.loss;
            //Info.Description = request.Description; 
            //Info.Remark = request.Remark;
            //Info.Netloss = request.Netloss;
            //Info.CreateDate = DateTime.Now;
            //return await accidentRepository.AddAsync(Info);
          
        }
    }
}
